{block name=body}
{function name=linking_list data=$data level=0 levelcount=0 order='5' table='tbl_additional_category' dfield='additional_category_product_id' dvalue='product_id' dvalue_val= $fields.product_id pkey='additional_category_id' skey='additional_category_listing_id' flag='additional_category_flag' preselectedArr=$preselectedArr existingArr=$fields.additional_category}
    {foreach $data as $opt}
        {if $count eq ""}
            {if $level eq 0}
            <input type="hidden" value="{$dvalue}" name="default[{$dfield}]" />
            {/if}
            {assign var=count value=1}
        {else}
            {assign var=count value=$count+1}
        {/if}
        {if $opt.extra.access_franchisee_id|in_array:$admin.franchisee || $admin.level eq 1} 
            <div class="row form-group">
                <input type="hidden" value="{$pkey}" name="field[{$order}][{$table}][{$levelcount*10}{$count}][id]" />
                <input type="hidden" value="{call name=fn_pkey id=$opt.id existingArr=$existingArr}" name="field[{$order}][{$table}][{$levelcount*10}{$count}][{$pkey}]" class="key"/>
                <input type="hidden" value="{$dvalue_val}" name="field[{$order}][{$table}][{$levelcount*10}{$count}][{$dfield}]" class="key">
                <input type="hidden" value="{$opt.id}" name="field[{$order}][{$table}][{$levelcount*10}{$count}][{$skey}]">
                <div class="col-sm-offset-3 col-sm-{$level+1}">
                    <input type="hidden" value="{call name=fn_value id=$opt.id existingArr=$existingArr preselectedArr=$preselectedArr}" name="field[{$order}][{$table}][{$levelcount*10}{$count}][{$flag}]" class="value">
                    <input style="float:right;" class="chckbx" type="checkbox" {call name=fn_selection id=$opt.id existingArr=$existingArr preselectedArr=$preselectedArr} onclick="if($(this).is(':checked')){ $(this).parent().children('.value').val('1') }else{ $(this).parent().children('.value').val('0') }" id="id_checkbox{$opt.id}">
                </div>
                <label style="text-align:left;" class="col-sm-3 control-label" for="id_checkbox{$opt.id}">{$opt.value}</label>
            </div>
        {/if}
        {if count($opt.subs) > 0}
            {call name=linking_list data=$opt.subs level=$level+1 levelcount=$levelcount+{$count} } 
        {/if}
    {/foreach} 
{/function}
{function name=fn_value id="" existingArr="" preselectedArr = ""}
    {assign var=val value=0}
    {if $id neq ""}
        {foreach $existingArr as $add}
            {if $id eq $add.$skey}
                {assign var=val value=$add.$flag}
                {break}
            {/if}
            {if $id|in_array:$preselectedArr}
                {assign var=val value=1}
                {break}
            {/if}
        {/foreach}
    {/if}
    {$val}
{/function}
{function name=fn_selection id="" existingArr="" preselectedArr = ""}
    {if $id neq ""}
        {foreach $existingArr as $add}
            {if $id eq $add.$skey}
                {if $add.$flag eq 1}checked="checked"{/if}
                {break}
            {/if}
            {if $id|in_array:$preselectedArr}checked="checked"{break}
            {/if}
        {/foreach}
    {/if}
{/function}
{function name=fn_pkey id="" existingArr=""}
    {if $id neq ""}
        {foreach $existingArr as $add}
            {if $id eq $add.$skey}
                {$add.$pkey}
                {break}
            {/if}
        {/foreach}
    {/if}
{/function}

{if $fields.location_franchisee_id|in_array:$admin.franchisee || $admin.level eq 1}
<div class="row">
    <div class="col-sm-12">
        <form class="well form-horizontal" id="Edit_Record" accept-charset="UTF-8" method="post">
            <div class="row">
                <div class="col-sm-12 edit-page-header">
                            <span class="edit-page-title">{if $fields.class_id neq ""}编辑{else}新建{/if} {$zone}</span>
                            {if $cnt eq ""}{assign var=cnt value=0}{/if} 
                            <a href="javascript:void(0);" onClick="$('#Edit_Record').submit();" class="btn btn-primary pull-right top-btn"><span class="glyphicon glyphicon-floppy-saved"></span> 保存</a>
                            {if $admin.level eq 1}
                            <div class="published" {if $fields.class_published eq 0}style="display:none;"{/if}>
                                <!-- 已发布 -->
                                <a href="javascript:void(0);" onClick="saveDraft('field[1][tbl_class][{$cnt}][id]','class_object_id','class_published','field[1][tbl_class][{$cnt}][class_deleted]',false);" class="btn btn-info pull-right top-btn published"><span class="glyphicon glyphicon-floppy-disk"></span> 保存草稿</a>
                                <a href="javascript:void(0);" onClick="unpublish('class_published');" class="btn btn-warning pull-right top-btn"><span class="glyphicon glyphicon-thumbs-down"></span> 不发布</a>
                            </div>
                            <div class="drafts" {if $fields.class_published eq 1}style="display:none;"{/if}>
                                <!-- 草稿 -->
                                <a href="javascript:void(0);" onClick="publish('field[1][tbl_class][{$cnt}][id]','class_object_id','class_published','field[1][tbl_class][{$cnt}][class_deleted]');" class="btn btn-primary pull-right top-btn drafts"><span class="glyphicon glyphicon-thumbs-up"></span> 保存 &amp; 发布</a>
                            </div>
                            {/if}
                    <input type="hidden" value="class_id" name="primary_id" id="primary_id"/> 
                    <input type="hidden" value="class_id" name="field[1][tbl_class][{$cnt}][id]" id="id" /> 
                    <input type="hidden" value="{$fields.class_id}" name="field[1][tbl_class][{$cnt}][class_id]" id="class_id" class="key"> 
                    <input type="hidden" value="{if $fields.class_object_id}{$fields.class_object_id}{else}{$objID}{/if}" name="field[1][tbl_class][{$cnt}][class_object_id]" id="class_object_id"> 
                    <input type="hidden" value="{if $fields.class_created}{$fields.class_created}{else}{'Y-m-d H:i:s'|date}{/if}" name="field[1][tbl_class][{$cnt}][class_created]" id="class_created">
                    <input type="hidden" value="{if $fields.class_published}1{else}0{/if}" name="field[1][tbl_class][{$cnt}][class_published]" id="class_published">
                    <input type="hidden" name="formToken" id="formToken" value="{$token}"/>
                </div>
            </div>
            <div class="row published" {if $fields.class_published eq 0}style="display:none;"{/if}>
                <div class="alert alert-success text-center">
                    <strong>已发布</strong> 
                </div>
            </div>
            <div class="row drafts" {if $fields.class_published eq 1}style="display:none;"{/if}>
                <div class="alert alert-info text-center">
                    <strong>草稿</strong>
                </div>
            </div>
            <ul class="nav nav-tabs" id="myTab">
                <li class="active"><a href="#details" data-toggle="tab">详情</a></li>
                <li><a href="#instructors" data-toggle="tab">教师</a></li>
                <li><a href="#log" data-toggle="tab">日志</a></li>
            </ul>
        
            <div class="tab-content">
                <!--===+++===+++===+++===+++===+++ DETAILS TAB +++===+++===+++===+++===+++====-->
                <div class="tab-pane active" id="details">
                    <div class="row form" data-error="<b>详情</b>选项上发现错误。打开<b>详情</b>选项以查看特定错误通知。">
                        <div class="row form-group" >
                            <label class="col-sm-3 control-label" for="id_class_instructors_id">* 教学地点</label>
                            <div class="col-sm-5">
{if $admin.level neq 1}
{foreach $fields.options.locations as $opt}
{if $fields.class_location_id eq $opt.id}
                                <span class="form-control">{$opt.value}</span>
{/if}
{/foreach}
                                <select style="display:none;" class="form-control required" name="field[1][tbl_class][{$cnt}][class_location_id]" id="id_class_location_id" onchange="updateName()">
                                    <option value="">请选择</option> {foreach $fields.options.locations as $opt}
                                    <option value="{$opt.id}" {if $fields.class_location_id && $fields.class_location_id eq $opt.id}selected="selected"{/if} data-location="{$opt.extra.location_suburb} {$opt.extra.location_state}">{$opt.value}</option> {/foreach}
                                </select>
{else}
                                <select class="form-control required" name="field[1][tbl_class][{$cnt}][class_location_id]" id="id_class_location_id" onchange="updateName()">
                                    <option value="">请选择</option> {foreach $fields.options.locations as $opt}
                                    <option value="{$opt.id}" {if $fields.class_location_id && $fields.class_location_id eq $opt.id}selected="selected"{/if} data-location="{$opt.extra.location_suburb} {$opt.extra.location_state}">{$opt.value}</option> {/foreach}
                                </select>
{/if}
                            </div>
                        </div>
                        <div class="row form-group">
                            <label class="col-sm-3 control-label">* 上课时间</label>
                            <div class="col-sm-9" id="classtime">
{if !$fields.classtime}
                                <div class="row">
                                	<input type="hidden" value="" name="field[2][tbl_classtime][classtime_class_id]">
                                    <div id="classtimehtml">
                                        <div class="col-sm-3">
                                            <select class="form-control required class_weekday" name="field[2][tbl_classtime][classtime_weekday][]" id="id_class_weekday" onchange="updateName()">
                                                <option value="">请选择</option>
                                                <option value="Sunday">星期日</option>
                                                <option value="Monday">星期一</option>
                                                <option value="Tuesday">星期二</option>
                                                <option value="Wednesday">星期三</option>
                                                <option value="Thursday">星期四</option>
                                                <option value="Friday">星期五</option>
                                                <option value="Saturday">星期六</option>
                                            </select>
                                        </div>
                                        <div class="col-sm-3">
                                            <select class="form-control required select" name="field[2][tbl_classtime][classtime_start_time][]" id="id_class_start_time" onchange="updateName()">
                                                <option value="">请选择</option>
                                                {for $h=5 to 22 }
                                                    {for $q=0 to 3 }
                                                        {assign var='time' value= $h|cat:":"|cat:$q*15}
                                                        {if $q eq 0}{assign var='time' value= $time|cat:"0"}{/if}
                                                        {if $h lt 10}{assign var='time' value= "0"|cat:$time}{/if}
                                                        <option value="{$time}:00">{$time}</option>
                                                    {/for}     
                                                {/for}
                                            </select>
                                        </div>
                                        <div class="col-sm-3">
                                            <select class="form-control required" name="field[2][tbl_classtime][classtime_end_time][]" id="id_class_end_time" onchange="updateName()">
                                                <option value="">请选择</option>
                                                {for $h=5 to 22 }
                                                    {for $q=0 to 3 }
                                                        {assign var='time' value= $h|cat:":"|cat:$q*15}
                                                        {if $q eq 0}{assign var='time' value= $time|cat:"0"}{/if}
                                                        {if $h lt 10}{assign var='time' value= "0"|cat:$time}{/if}
                                                        <option value="{$time}:00">{$time}</option>
                                                    {/for}     
                                                {/for}
                                            </select>
                                        </div>
                                    </div>
                                    <a href="javascript:void(0);" class="btn btn-info btn-sm marg-5r edit-name" onclick="addClassTime()">添加安排</a>
                                </div>
{else}
	{foreach from=$fields.classtime item=classtime name=attr}
		{if $smarty.foreach.attr.first}
                                <div class="row">
                                    <input type="hidden" value="{$fields.class_id}" name="field[2][tbl_classtime][classtime_class_id]">
                                    <div id="classtimehtml">
                                        <div class="col-sm-3">
                                            <select class="form-control required class_weekday" name="field[2][tbl_classtime][classtime_weekday][]" id="id_class_weekday" onchange="updateName()">
                                                <option value="">请选择</option>
                                                <option value="Sunday" {if $classtime.classtime_weekday eq 'Sunday'}selected="selected"{/if}>星期日</option>
                                                <option value="Monday" {if $classtime.classtime_weekday eq 'Monday'}selected="selected"{/if}>星期一</option>
                                                <option value="Tuesday" {if $classtime.classtime_weekday eq 'Tuesday'}selected="selected"{/if}>星期二</option>
                                                <option value="Wednesday" {if $classtime.classtime_weekday eq 'Wednesday'}selected="selected"{/if}>星期三</option>
                                                <option value="Thursday" {if $classtime.classtime_weekday eq 'Thursday'}selected="selected"{/if}>星期四</option>
                                                <option value="Friday" {if $classtime.classtime_weekday eq 'Friday'}selected="selected"{/if}>星期五</option>
                                                <option value="Saturday" {if $classtime.classtime_weekday eq 'Saturday'}selected="selected"{/if}>星期六</option>
                                            </select>
                                        </div>
                                        <div class="col-sm-3">
                                            <select class="form-control required select" name="field[2][tbl_classtime][classtime_start_time][]" id="id_class_start_time" onchange="updateName()">
                                                <option value="">请选择</option>
                                                {for $h=5 to 22 }
                                                    {for $q=0 to 3 }
                                                        {assign var='time' value= $h|cat:":"|cat:$q*15}
                                                        {if $q eq 0}{assign var='time' value= $time|cat:"0"}{/if}
                                                        {if $h lt 10}{assign var='time' value= "0"|cat:$time}{/if}
                                                        <option value="{$time}:00" {if $classtime.classtime_start_time eq $time|cat:":00" }selected="selected"{/if}>{$time}</option>
                                                    {/for}     
                                                {/for}
                                            </select>
                                        </div>
                                        <div class="col-sm-3">
                                            <select class="form-control required" name="field[2][tbl_classtime][classtime_end_time][]" id="id_class_end_time" onchange="updateName()">
                                                <option value="">请选择</option>
                                                {for $h=5 to 22 }
                                                    {for $q=0 to 3 }
                                                        {assign var='time' value= $h|cat:":"|cat:$q*15}
                                                        {if $q eq 0}{assign var='time' value= $time|cat:"0"}{/if}
                                                        {if $h lt 10}{assign var='time' value= "0"|cat:$time}{/if}
                                                        <option value="{$time}:00" {if $classtime.classtime_end_time eq $time|cat:":00"}selected="selected"{/if}>{$time}</option>
                                                    {/for}     
                                                {/for}
                                            </select>
                                        </div>
                                    </div>
                                    <a href="javascript:void(0);" class="btn btn-info btn-sm marg-5r edit-name" onclick="addClassTime()">添加安排</a>
                                </div>
		{else}
                                <div class="row">
                                    <div class="col-sm-3">
                                        <select class="form-control required class_weekday" name="field[2][tbl_classtime][classtime_weekday][]">
                                            <option value="">请选择</option>
                                            <option value="Sunday" {if $classtime.classtime_weekday eq 'Sunday'}selected="selected"{/if}>星期日</option>
                                            <option value="Monday" {if $classtime.classtime_weekday eq 'Monday'}selected="selected"{/if}>星期一</option>
                                            <option value="Tuesday" {if $classtime.classtime_weekday eq 'Tuesday'}selected="selected"{/if}>星期二</option>
                                            <option value="Wednesday" {if $classtime.classtime_weekday eq 'Wednesday'}selected="selected"{/if}>星期三</option>
                                            <option value="Thursday" {if $classtime.classtime_weekday eq 'Thursday'}selected="selected"{/if}>星期四</option>
                                            <option value="Friday" {if $classtime.classtime_weekday eq 'Friday'}selected="selected"{/if}>星期五</option>
                                            <option value="Saturday" {if $classtime.classtime_weekday eq 'Saturday'}selected="selected"{/if}>星期六</option>
                                        </select>
                                    </div>
                                    <div class="col-sm-3">
                                        <select class="form-control required select" name="field[2][tbl_classtime][classtime_start_time][]">
                                            <option value="">请选择</option>
                                            {for $h=5 to 22 }
                                                {for $q=0 to 3 }
                                                    {assign var='time' value= $h|cat:":"|cat:$q*15}
                                                    {if $q eq 0}{assign var='time' value= $time|cat:"0"}{/if}
                                                    {if $h lt 10}{assign var='time' value= "0"|cat:$time}{/if}
                                                    <option value="{$time}:00" {if $classtime.classtime_start_time eq $time|cat:":00" }selected="selected"{/if}>{$time}</option>
                                                {/for}     
                                            {/for}
                                        </select>
                                    </div>
                                    <div class="col-sm-3">
                                        <select class="form-control required" name="field[2][tbl_classtime][classtime_end_time][]">
                                            <option value="">请选择</option>
                                            {for $h=5 to 22 }
                                                {for $q=0 to 3 }
                                                    {assign var='time' value= $h|cat:":"|cat:$q*15}
                                                    {if $q eq 0}{assign var='time' value= $time|cat:"0"}{/if}
                                                    {if $h lt 10}{assign var='time' value= "0"|cat:$time}{/if}
                                                    <option value="{$time}:00" {if $classtime.classtime_end_time eq $time|cat:":00"}selected="selected"{/if}>{$time}</option>
                                                {/for}     
                                            {/for}
                                        </select>
                                    </div>
                                    <a href="javascript:void(0);" class="btn btn-danger btn-sm marg-5r edit-name" onclick="delClassTime(this)">删除本条</a>
                                </div>
		{/if}
	{/foreach}
{/if}
                            </div>
                        </div>
                        <div class="row form-group">
                            <label class="col-sm-3 control-label" for="id_class_agegroup_id">* 年龄段</label>
                            <div class="col-sm-3">
                                <select class="form-control required" name="field[1][tbl_class][{$cnt}][class_agegroup_id]" id="id_class_agegroup_id" onchange="updateName()">
                                    <option value="">请选择</option> {foreach $fields.options.agegroups as $opt}
                                    <option value="{$opt.id}" {if $fields.class_agegroup_id eq $opt.id}selected="selected"{/if}>{$opt.value}</option> {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="row form-group">
                            <label class="col-sm-3 control-label" for="id_class_agegroup_id">* 班级</label>
                            <div class="col-sm-3">
                                <select class="form-control required" name="field[1][tbl_class][{$cnt}][class_num]" id="id_class_num" onchange="updateName()">
                                    <option value="">请选择</option>
                                    <option value="0" {if $fields.class_num eq 0}selected="selected"{/if}>OPEN CLASS</option>
                                    <option value="1" {if $fields.class_num eq 1}selected="selected"{/if}>一班</option>
                                    <option value="2" {if $fields.class_num eq 2}selected="selected"{/if}>二班</option>
                                    <option value="3" {if $fields.class_num eq 3}selected="selected"{/if}>三班</option>
                                    <option value="4" {if $fields.class_num eq 4}selected="selected"{/if}>四班</option>
                                    <option value="5" {if $fields.class_num eq 5}selected="selected"{/if}>五班</option>
                                    <option value="6" {if $fields.class_num eq 6}selected="selected"{/if}>六班</option>
                                    <option value="7" {if $fields.class_num eq 7}selected="selected"{/if}>七班</option>
                                    <option value="8" {if $fields.class_num eq 8}selected="selected"{/if}>八班</option>
                                    <option value="9" {if $fields.class_num eq 9}selected="selected"{/if}>九班</option>
                                    <option value="10" {if $fields.class_num eq 10}selected="selected"{/if}>十班</option>
                                    <option value="11" {if $fields.class_num eq 11}selected="selected"{/if}>十一班</option>
                                    <option value="12" {if $fields.class_num eq 12}selected="selected"{/if}>十二班</option>
                                    <option value="13" {if $fields.class_num eq 13}selected="selected"{/if}>十三班</option>
                                    <option value="14" {if $fields.class_num eq 14}selected="selected"{/if}>十四班</option>
                                    <option value="15" {if $fields.class_num eq 15}selected="selected"{/if}>十五班</option>
                                </select>
                            </div>
                        </div>
                        <div class="row form-group" {if $admin.level neq 1}style="display:none;"{/if}>
                            <label class="col-sm-3 control-label" for="id_class_name">名称 *</label>
                            <div class="col-sm-7">
                                <input class="form-control" type="hidden" value="{$fields.class_name}" name="field[1][tbl_class][{$cnt}][class_name]" id="id_class_name" required>
                                <span id="id_class_name_text" class="form-control url-text edit-name">{$fields.class_name}</span>
                                <a href="javascript:void(0);" class="btn btn-info btn-sm marg-5r edit-name" onclick="$('.edit-name').removeClass('url-text').hide();$('#id_class_name').get(0).type='text';">编辑名称</a>
                                <span class="help-block"></span>
                            </div>
                        </div>
                        <div class="row form-group" {if $admin.level neq 1}style="display:none;"{/if}>
                            <label class="col-sm-3 control-label" for="id_class_url">* URL地址</label>
                            <div class="col-sm-7">
                                <input class="form-control" type="hidden" value="{$fields.class_url}" name="field[1][tbl_class][{$cnt}][class_url]" id="id_class_url" onchange="seturl();" >
                				<span id="id_class_url_text" class="form-control url-text edit-url">{$fields.class_url}</span>
                				<a href="javascript:void(0);" class="btn btn-info btn-sm marg-5r edit-url" onclick="$('.edit-url').removeClass('url-text').hide();$('#id_class_url').get(0).type='text';">编辑URL地址</a> 
                                <span class="help-block"></span>
                            </div>
                        </div>
                        <div class="row form-group" {if $admin.level neq 1}style="display:none;"{/if}>
                            <label class="col-sm-3 control-label" for="id_class_seo_title">SEO 标题 *</label>
                            <div class="col-sm-5">
                                <input class="form-control" type="text" value="{$fields.class_seo_title}" name="field[1][tbl_class][{$cnt}][class_seo_title]" id="id_class_seo_title" required>
                                <span class="help-block"></span>
                            </div>
                        </div>
                        <div class="row form-group" {if $admin.level neq 1}style="display:none;"{/if}>
                            <label class="col-sm-3 control-label" for="id_class_content1">描述</label>
                            <div class="col-sm-5">
                                <textarea name="field[1][tbl_class][{$cnt}][class_content1]" id="id_class_content1" class="tinymce">{$fields.class_content1}</textarea>
                            </div>
                        </div>
                        <div class="row form-group">
                            <label class="col-sm-3 control-label" for="id_class_content1">运动项目</label>
                            <div class="col-sm-8">
                                <table id="sport-table" class="visible-lg visible-md">
                                    <tbody>
                                        <tr>
                                        <!-- <td> <label for="sport_a1">场地 A</label></td> -->
                                        <td class="text-center"><img src="/images/athletics.png" alt="Athletics" /><br /> 田径</td>
                                        <td class="text-center"><img src="/images/basketball.png" alt="Basketball" /><br /> 篮球</td>
                                        <td class="text-center"><img src="/images/golf.png" alt="Golf" /><br /> 高尔夫</td>
                                        <td class="text-center"><img src="/images/rugby.png" alt="Rugby" /><br /> 英式橄榄球</td>
                                        <td class="text-center"><img src="/images/tball.png" alt="T-ball" /><br /> 儿童棒球</td>
                                        </tr>
                                        <tr>
                                        <!-- <td><label for="sport_b1">场地 B</label></td> -->
                                        <td class="text-center"><img src="/images/soccer.png" alt="Soccer" /><br /> 足球</td>
                                        <td class="text-center"><img src="/images/tennis.png" alt="Tennis" /><br /> 网球</td>
                                        <td class="text-center"><img src="/images/hockey.png" alt="Hockey" /><br /> 曲棍球</td>
                                        <td class="text-center"><img src="/images/aflrugby.png" alt="AFL" /><br /> 澳式足球</td>
                                        <td class="text-center"><img src="/images/cricket.png" alt="Cricket" /><br /> 板球</td>
                                        </tr>
                                    </tbody>
                                </table>
                                <table id="resulttable" class="hidden-lg hidden-md sports-table">
                                    <thead>
                                        <tr>
                                            <!-- <th><label for="sport_a2">场地 A</label></th>
                                            <th><label for="sport_b2">场地 B</label></th> -->
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                        <td class="text-center"><img src="/images/athletics.png" alt="Athletics" /><br /> 田径</td>
                                        <td class="text-center"><img src="/images/soccer.png" alt="Soccer" /><br /> 足球</td>
                                        </tr>
                                        <tr>
                                        <td class="text-center"><img src="/images/basketball.png" alt="Basketball" /><br /> 篮球</td>
                                        <td class="text-center"><img src="/images/tennis.png" alt="Tennis" /><br /> 网球</td>
                                        </tr>
                                        <tr>
                                        <td class="text-center"><img src="/images/golf.png" alt="Golf" /><br /> 高尔夫</td>
                                        <td class="text-center"><img src="/images/hockey.png" alt="Hockey" /><br /> 曲棍球</td>
                                        </tr>
                                        <tr>
                                        <td class="text-center"><img src="/images/rugby.png" alt="Rugby" /><br /> 英式橄榄球</td>
                                        <td class="text-center"><img src="/images/aflrugby.png" alt="AFL" /><br /> 澳式足球</td>
                                        </tr>
                                        <tr>
                                        <td class="text-center"><img src="/images/tball.png" alt="T-ball" /><br /> 儿童棒球</td>
                                        <td class="text-center"><img src="/images/cricket.png" alt="Cricket" /><br /> 板球</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        <!-- <div class="row form-group">
                            <label class="col-sm-3 control-label" for="id_class_sports1">学期 1 运动 *</label>
                            <div class="col-sm-3">
                                <select class="form-control required" name="field[1][tbl_class][{$cnt}][class_sports1]" id="id_class_sports1">
                                    <option value="0">请选择</option>
                                    <option value="1" {if $fields.class_sports1 eq '1'}selected="selected"{/if}>场地 A</option>
                                    <option value="2" {if $fields.class_sports1 eq '2'}selected="selected"{/if}>场地 B</option>
                                </select>
                            </div>
                        </div>
                        <div class="row form-group">
                            <label class="col-sm-3 control-label" for="id_class_sports2">学期 2 运动 *</label>
                            <div class="col-sm-3">
                                <select class="form-control required" name="field[1][tbl_class][{$cnt}][class_sports2]" id="id_class_sports2">
                                    <option value="0">请选择</option>
                                    <option value="1" {if $fields.class_sports2 eq '1'}selected="selected"{/if}>场地 A</option>
                                    <option value="2" {if $fields.class_sports2 eq '2'}selected="selected"{/if}>场地 B</option>
                                </select>
                            </div>
                        </div>
                        <div class="row form-group">
                            <label class="col-sm-3 control-label" for="id_class_sports3">学期 3 运动 *</label>
                            <div class="col-sm-3">
                                <select class="form-control required" name="field[1][tbl_class][{$cnt}][class_sports3]" id="id_class_sports3">
                                    <option value="0">请选择</option>
                                    <option value="1" {if $fields.class_sports3 eq '1'}selected="selected"{/if}>场地 A</option>
                                    <option value="2" {if $fields.class_sports3 eq '2'}selected="selected"{/if}>场地 B</option>
                                </select>
                            </div>
                        </div>
                        <div class="row form-group">
                            <label class="col-sm-3 control-label" for="id_class_sports4">学期 4 运动 *</label>
                            <div class="col-sm-3">
                                <select class="form-control required" name="field[1][tbl_class][{$cnt}][class_sports4]" id="id_class_sports4">
                                    <option value="0">请选择</option>
                                    <option value="1" {if $fields.class_sports4 eq '1'}selected="selected"{/if}>场地 A</option>
                                    <option value="2" {if $fields.class_sports4 eq '2'}selected="selected"{/if}>场地 B</option>
                                </select>
                            </div>
                        </div>
                        <div class="row form-group">
                            <label class="col-sm-3 control-label" for="id_class_sports4">学期 5 运动 *</label>
                            <div class="col-sm-3">
                                <select class="form-control required" name="field[1][tbl_class][{$cnt}][class_sports5]" id="id_class_sports5">
                                    <option value="0">请选择</option>
                                    <option value="1" {if $fields.class_sports5 eq '1'}selected="selected"{/if}>场地 A</option>
                                    <option value="2" {if $fields.class_sports5 eq '2'}selected="selected"{/if}>场地 B</option>
                                </select>
                            </div>
                        </div> -->
                        
                        <div class="row form-group" {if $admin.level neq 1}style="display:none;"{/if}>
                            <label class="col-sm-3 control-label" for="id_class_meta_description">Meta 描述</label>
                            <div class="col-sm-5">
                                <input class="form-control" type="text" value="{$fields.class_meta_description}" name="field[1][tbl_class][{$cnt}][class_meta_description]" id="id_class_meta_description">
                            </div>
                        </div>
                        <div class="row form-group" {if $admin.level neq 1}style="display:none;"{/if}>
                            <label class="col-sm-3 control-label" for="id_class_meta_words">Meta 关键字</label>
                            <div class="col-sm-5">
                                <input class="form-control" type="text" value="{$fields.class_meta_words}" name="field[1][tbl_class][{$cnt}][class_meta_words]" id="id_class_meta_words">
                            </div>
                        </div>
                        
                        <div class="row form-group" {if $admin.level neq 1}style="display:none;"{/if}>
                            <label class="col-sm-3 control-label" for="id_class_size">招生人数 *</label>
                            <div class="col-sm-5">
                                <input class="form-control number" type="text" value="{$fields.class_size}" name="field[1][tbl_class][{$cnt}][class_size]" id="id_class_size" required>
                            </div>
                        </div>
                        <div class="row form-group" {if $admin.level neq 1}style="display:none;"{/if}>
                            <label class="col-sm-3 control-label" for="id_class_price">价格({$CURRENCY_SYMBOL}) *</label>
                            <div class="col-sm-5">
                                <input class="form-control double" type="text" value="{$fields.class_price}" name="field[1][tbl_class][{$cnt}][class_price]" id="id_class_price" required>
                            </div>
                        </div>
                        <div class="row form-group" {if $admin.level neq 1}style="display:none;"{/if}>
                            <label class="col-sm-3 control-label" for="id_class_special_price">特价({$CURRENCY_SYMBOL})</label>
                            <div class="col-sm-5">
                                <input class="form-control double" type="text" value="{$fields.class_special_price}" name="field[1][tbl_class][{$cnt}][class_special_price]" id="id_class_special_price">
                            </div>
                        </div>
                        <div class="row form-group" {if $admin.level neq 1}style="display:none;"{/if}>
                            <label class="col-sm-3 control-label" for="id_class_product_id">制服</label>
                            <div class="col-sm-5">
                                <select class="form-control" name="field[1][tbl_class][{$cnt}][class_product_id]" id="id_class_product_id">
                                    <option value="">请选择</option> {foreach $fields.options.products as $opt}
                                    <option value="{$opt.id}" {if $fields.class_product_id eq $opt.id}selected="selected"{/if}>{$opt.value}</option> {/foreach}
                                </select>
                            </div>
                        </div>
                        
                        </div>
                </div>
                <!--===+++===+++===+++===+++===+++ INSTRUCTORS TAB +++===+++===+++===+++===+++====-->
                <div class="tab-pane" id="instructors">
                    <div class="row form" id="tags-wrapper" data-error="Error found on <b>Instructors tab</b>. View <b>Instructors tab</b> to see specific error notices.">
                        <div class="col-sm-12">
                            {call name=linking_list data=$fields.options.instructors level=0 levelcount=0 order='5' table='tbl_class_instructor' dfield='class_instructor_class_id' dvalue='class_id' 
                            dvalue_val= $fields.class_id pkey='class_instructor_id' skey='class_instructor_admin_id' flag='class_instructor_flag' 
                            preselectedArr=$preselectedArr existingArr=$fields.classinstructors} 
                        </div>
                    </div>
                </div>
                <!--===+++===+++===+++===+++===+++ LOG TAB +++===+++===+++===+++===+++====-->
                <div class="tab-pane" id="log">
                    <div class="row form" id="tags-wrapper">
                        <div class="col-sm-12">
                            {if $fields.logs}
                                <table class="table table-bordered table-striped table-hover">
                                    <thead>
                                        <tr>
                                            <th>时间</td>
                                            <th>操作</td>
                                            <th>用户</td>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    {foreach $fields.logs as $log}
                                        <tr {if $log.class_id eq $fields.class_id}class="info"{/if}>
                                            <td>{$log.log_created|date_format:"%d/%b/%Y %r"}</td>
                                            <td>{$log.log_action}{if $log.log_action eq 'Add' || $log.log_action eq 'Delete'} draft{/if}</td>
                                            <td>{$log.admin_name}</td>
                                        </tr>
                                    {/foreach}
                                    </tbody>
                                </table>
                            {else}
                                暂无日志。
                            {/if}
                        </div>
                    </div>
                </div>
            </div>
            <div class="row form-group form-bottom-btns">
                <a href="javascript:void(0);" onClick="$('#Edit_Record').submit();" class="btn btn-primary pull-right top-btn"><span class="glyphicon glyphicon-floppy-saved"></span> 保存</a>
                {if $admin.level eq 1}
                <div class="published" {if $fields.class_published eq 0}style="display:none;"{/if}>
                    <!-- 已发布 -->
                    <a href="javascript:void(0);" onClick="saveDraft('field[1][tbl_class][{$cnt}][id]','class_object_id','class_published','field[1][tbl_class][{$cnt}][class_deleted]', false);" class="btn btn-info pull-right top-btn published"><span class="glyphicon glyphicon-floppy-disk"></span> 保存草稿</a>
                    <a href="javascript:void(0);" onClick="unpublish('class_published');" class="btn btn-warning pull-right top-btn"><span class="glyphicon glyphicon-thumbs-down"></span> 不发布</a>
                </div>
                <div class="drafts" {if $fields.class_published eq 1}style="display:none;"{/if}>
                    <!-- 草稿 -->
                    <a href="javascript:void(0);" onClick="publish('field[1][tbl_class][{$cnt}][id]','class_object_id','class_published','field[1][tbl_class][{$cnt}][class_deleted]');" class="btn btn-primary pull-right top-btn drafts"><span class="glyphicon glyphicon-thumbs-up"></span> 保存 &amp; 发布</a>
                </div>
                {/if}
            </div>
        </form>
    </div>
</div>

{include file='jquery-validation.tpl'}

<script type="text/javascript">
function addClassTime(){
    var classtime = $("#classtimehtml").clone();
    var classtimehtml = '<div class="row">'+classtime.html()+'<a href="javascript:void(0);" class="btn btn-danger btn-sm marg-5r edit-name" onclick="delClassTime(this)">删除本条</a></div>';
    $("#classtime").append(classtimehtml);
}

function delClassTime(which){
    $(which).parent(".row").remove();
}


function seturl(){
	var weekday = '';
	$(".class_weekday").each(function(index, el) {
		weekday += $(this).find("option:selected").val()+'-';
	});
    var url = $('#id_class_location_id option:selected').val() + '-' + weekday + $('#id_class_agegroup_id').val()+'-'+$('#id_class_num').val();
    $.ajax({
        type: "POST",
        url: "/admin/includes/processes/urlencode.php",
        cache: false,
        data: "value="+encodeURIComponent(url),
        dataType: "json",
        success: function(res, textStatus) {
            try{
                //if($('#class_id').val() == "" || editexisting == true){
                $('#id_class_url').val(res.url);
                $('#id_class_url_text').html(res.url);
                //}
            }catch(err){ }
        }
    });
}

function updateName(){
	var weekday = '';
	$(".class_weekday").each(function(index, el) {
		weekday += $(this).find("option:selected").text()+' | ';
	});
    var newname = $('#id_class_location_id option:selected').text() + ' | ' + weekday + $('#id_class_agegroup_id option:selected').text() + ' | ' + $('#id_class_num option:selected').text();
    $('#id_class_name').val(newname);
    $('#id_class_name_text').html(newname);
    seturl();
    $('#id_class_seo_title').val(newname);
}

$(document).ready(function(){

    $('#Edit_Record').validate({
        onkeyup: false
    });
    
    $('#id_class_url').rules("add", {
          uniqueURL: { 
                  id: $('#class_object_id').val(),
                  idfield: "class_object_id",
                table : "tbl_class",
                field : "class_url",
                field2 : "",
                value2 : ""
          }
     });
});

function saveDraft(id_name,objId_name,publish_name, field_name, preview){
    if ($('#Edit_Record').valid()) {
        $('body').css('cursor', 'wait');
        $('#'+publish_name).val('0');
        var id_key0 = encodeURIComponent(id_name+'[0]');
        var id_key1 = encodeURIComponent(id_name+'[1]');
        var objId_key = encodeURIComponent($('#'+objId_name).attr('name'));
        var publish_key = encodeURIComponent($('#'+publish_name).attr('name'));
        var field_key = encodeURIComponent(field_name);
        var field_value = encodeURIComponent(mysql_now());
        $.ajax({
            type : "POST",
            url : "/admin/includes/processes/processes-record.php",
            cache: false,
            async: false,
            data : id_key0+'='+objId_name+'&'+id_key1+'='+publish_name+'&'+objId_key+"="+$('#'+objId_name).val()+"&"+publish_key+"=0&"+field_key+"="+field_value+'&formToken='+$('#formToken').val(),
            dataType: "html",
            success : function(data, textStatus) {
                try {
                    var obj = $.parseJSON(data);
                    if(obj.notice){ 
                        $('.key').val('');
                        $('#Edit_Record').submit();
                        $('.published').hide();
                        $('.drafts').show();
                        buildUrl('tbl_class','class_parent_id',objId_name, preview);
                    }
                } catch (err) {}
                $('body').css('cursor', 'default');
            }
        });
        $('body').css('cursor', 'default');
    } 
}

function publish(id_name,objId_name,publish_name,field_name){
    if ($('#Edit_Record').valid()) { 
        $('body').css('cursor', 'wait');
        $('#'+publish_name).val('1');
        var id_key0 = encodeURIComponent(id_name+'[0]');
        var id_key1 = encodeURIComponent(id_name+'[1]');
        var objId_key = encodeURIComponent($('#'+objId_name).attr('name'));
        var publish_key = encodeURIComponent($('#'+publish_name).attr('name'));
        var field_key = encodeURIComponent(field_name);
        var field_value = encodeURIComponent(mysql_now());
        $.ajax({
            type : "POST",
            url : "/admin/includes/processes/processes-record.php",
            cache: false,
            data : id_key0+'='+objId_name+'&'+id_key1+'='+publish_name+'&'+objId_key+"="+$('#'+objId_name).val()+"&"+publish_key+"=1&"+field_key+"="+field_value+'&formToken='+$('#formToken').val(),
            dataType: "html",
            success : function(data, textStatus) {
                try {
                    var obj = $.parseJSON(data);
                    if(obj.notice){ 
                        $('#Edit_Record').submit();
                        $('.drafts').hide();
                        $('.published').show();
                    }
                } catch (err) {}
                $('body').css('cursor', 'default');
            }
        });
        $('body').css('cursor', 'default');
    } 
}

function unpublish(publish_name){
    $('#'+publish_name).val('0');
    $('#Edit_Record').submit();
    $('.published').hide();
    $('.drafts').show();
}

</script>
{/if}
{/block}
